<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>轮播图编辑</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layui/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layui/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" value="${IndexSlide.id}">

    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">上传轮播图</label>
        <div class="layui-input-block">
            <button type="button" name="imagePath" class="layui-btn" id="imagePath">
                <i class="layui-icon">&#xe67c;</i>上传图片
            </button>

        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">跳转方式</label>
        <div class="layui-input-block">
            <input type="text" name="url" lay-verify="required" lay-reqtext="跳转方式不能为空" value="${IndexSlide.url}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort"  value="${IndexSlide.sort}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">备注</label>
        <div class="layui-input-block">
            <input type="text" name="descs"  value="${IndexSlide.descs}" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="开启" <c:if test="${IndexSlide.status == '1'}">checked</c:if>>
            <input type="radio" name="status" value="2" title="关闭" <c:if test="${IndexSlide.status == '2'}">checked</c:if>>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script src="/layui/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'upload', 'layedit'], function () {
        var form = layui.form,
            layer = layui.layer,
            upload = layui.upload,
            layedit = layui.layedit,
            $ = layui.$;

        // 上传图片
        var uploadInst = upload.render({
            elem: '#imagePath', //绑定元素
            url: '/operating/files', //上传接口
            done: function(res){
                //上传完毕回调
                layer.msg('上传成功');
            },
            error: function(){
                //请求异常回调
                layer.msg('上传失败，未知错误');
            }
        });

        //监听提交
        form.on('submit(saveBtn)', function (data) {

            $.ajax({
                url: '/operating/modify',
                type: 'post',
                data: JSON.stringify(data.field),
                contentType: 'application/json',
                dataType: 'json',
                success: function (result) {
                    if (result.code == '0') {
                        // 关闭弹出层
                        layer.close();
                        // 刷新上一层页面
                        parent.window.location.reload();
                    }
                }
            });

            return false;
        });

    });
</script>
</body>
</html>